package com.tmeone.erpone.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tmeone.erpone.entity.JsonResult;
import com.tmeone.erpone.entity.SRoleMenu;
import com.tmeone.erpone.service.ISRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tmeone
 * @since 2021-04-16
 */
@RestController
public class SRoleMenuController {


    @Autowired
    private ISRoleMenuService roleFunService;

    @RequestMapping(value = "/role-functions",method = RequestMethod.POST)
    public JsonResult addRoleFunctions(@RequestBody SRoleMenu roleFun){
        roleFunService.save(roleFun);
        //考虑是上级权限的情况
        return new JsonResult(1,roleFun);
    }

    @RequestMapping( value = "/role-functions/{roleId}/{functionsId}",method = RequestMethod.DELETE)
    public JsonResult deleteRoleFunctions(@PathVariable String roleId, @PathVariable String functionsId){
        roleFunService.remove(new QueryWrapper<SRoleMenu>()
                .lambda()
                .eq(SRoleMenu::getRoleId,roleId)
                .eq(SRoleMenu::getMenuId,functionsId));
        //考虑是上级权限的情况
        return new JsonResult(1,null);
    }
}
